BX.namespace("BX.UI");if(typeof BX.UI.EntityConfigType==="undefined"){BX.UI.EntityConfigType={COLUMN:"column",SECTION:"section",INCLUDED_AREA:"included_area",FIELD:"field"}}if(typeof BX.UI.EntityConfigFactory==="undefined"){BX.UI.EntityConfigFactory={createByType:function(t,e){var i;if(t===BX.UI.EntityConfigType.COLUMN){i=BX.UI.EntityConfigColumn.create(e)}else if(t===BX.UI.EntityConfigType.SECTION){i=BX.UI.EntityConfigSection.create(e)}else if(t===BX.UI.EntityConfigType.INCLUDED_AREA){i=BX.UI.EntityConfigIncludedArea.create(e)}else{i=BX.UI.EntityConfigField.create(e)}return i}}}if(typeof BX.UI.EntityConfig==="undefined"){BX.UI.EntityConfig=function(){this._id="";this._settings={};this._scope=BX.UI.EntityConfigScope.undefined;this._userScopes=null;this._userScopeId=null;this._enableScopeToggle=true;this._canUpdatePersonalConfiguration=true;this._canUpdateCommonConfiguration=false;this._data={};this._items=[];this._options={};this._isChanged=false;this.categoryName="";this.moduleId=""};BX.UI.EntityConfig.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._scope=BX.prop.getString(this._settings,"scope",BX.UI.EntityConfigScope.personal);this._userScopes=BX.prop.getObject(this._settings,"userScopes",null);this._userScopeId=BX.prop.getString(this._settings,"userScopeId",null);this.moduleId=BX.prop.getString(this._settings,"moduleId",null);this._enableScopeToggle=BX.prop.getBoolean(this._settings,"enableScopeToggle",true);this._canUpdatePersonalConfiguration=BX.prop.getBoolean(this._settings,"canUpdatePersonalConfiguration",true);this._canUpdateCommonConfiguration=BX.prop.getBoolean(this._settings,"canUpdateCommonConfiguration",false);this._data=BX.prop.getArray(this._settings,"data",[]);this._items=[];for(var i=0,n=this._data.length;i<n;i++){var o=this._data[i];var s=BX.prop.getString(o,"type","");var r=BX.UI.EntityConfigFactory.createByType(s,{data:o});this._items.push(r)}this._options=BX.prop.getObject(this._settings,"options",{});this.categoryName=BX.prop.getString(this._settings,"categoryName","ui.form.editor")},findItemByName:function(t){for(var e=0,i=this._items.length;e<i;e++){var n=this._items[e];if(n.getName()===t){return n}}return null},findItemIndexByName:function(t){for(var e=0,i=this._items.length;e<i;e++){var n=this._items[e];if(n.getName()===t){return e}}return-1},toJSON:function(){var t=[];for(var e=0,i=this._items.length;e<i;e++){t.push(this._items[e].toJSON())}return t},addSchemeElementAt:function(t,e){var i=BX.UI.EntityConfigFactory.createByType(t.getType(),{data:t.createConfigItem()});if(e>=0&&e<this._items.length){this._items.splice(e,0,i)}else{this._items.push(i)}this._isChanged=true},moveSchemeElement:function(t,e){var i=this._items.length;var n=i-1;if(e<0||e>i){e=n}var o=this.findItemIndexByName(t.getName());if(o<0||o===e){return}var s=this._items[o];this._items.splice(o,1);i--;if(e<i){this._items.splice(e,0,s)}else{this._items.push(s)}this._isChanged=true},updateSchemeElement:function(t){var e;var i=t.getParent();if(i&&i.getType()==="section"){var n=this.findItemByName(i.getName());if(n){e=n.findFieldIndexByName(t.getName());if(e>=0){var o=BX.UI.EntityConfigFactory.createByType(BX.UI.EntityConfigType.FIELD,{data:t.createConfigItem()});n.setField(o,e);this._isChanged=true}}}else{e=this.findItemIndexByName(t.getName());if(e>=0){this._items[e]=BX.UI.EntityConfigFactory.createByType(t.getType(),{data:t.createConfigItem()});this._isChanged=true}}},removeSchemeElement:function(t){var e=this.findItemIndexByName(t.getName());if(e<0){return}this._items.splice(e,1);this._isChanged=true},isChangeable:function(){if(this._scope===BX.UI.EntityConfigScope.common||this._scope===BX.UI.EntityConfigScope.custom){return this._canUpdateCommonConfiguration}else if(this._scope===BX.UI.EntityConfigScope.personal){return this._canUpdatePersonalConfiguration}return false},isCanChangeCommonConfiguration:function(){return this._canUpdateCommonConfiguration},isChanged:function(){return this._isChanged},isScopeToggleEnabled:function(){return this._enableScopeToggle},getScope:function(){return this._scope},setScope:function(t,e,i){var n=new BX.Promise;if(!this._enableScopeToggle||this._scope===t&&t!==BX.UI.EntityConfigScope.custom||this._scope===t&&this._userScopeId===e){window.setTimeout(function(){n.fulfill()},0);return n}this._scope=t;this._userScopeId=e;this.moduleId=i;this._data=[];this._items=[];BX.ajax.runComponentAction("bitrix:ui.form.config","setScope",{data:{categoryName:this.categoryName,moduleId:this.moduleId,guid:this._id,scope:this._scope,userScopeId:this._userScopeId||0}}).then(function(t){n.fulfill()});return n},registerField:function(t){var e=t.getParent();if(!e){return}var i=this.findItemByName(e.getName());if(!i){return}i.addField(BX.UI.EntityConfigField.create({data:t.createConfigItem()}));this.save()},unregisterField:function(t){var e=t.getParent();if(!e){return}var i=this.findItemByName(e.getName());if(!i){return}var n=i.findFieldByName(t.getName());if(!n){return}i.removeFieldByIndex(n.getIndex());this.save()},save:function(t,e){t=!!t;e=!!e;var i=new BX.Promise;if(!this._isChanged&&!t){window.setTimeout(function(){i.fulfill()},0);return i}var n={guid:this._id,config:this.toJSON(),params:{scope:this._scope},categoryName:this.categoryName};if(e){n["params"]["options"]=this._options}if(t){n["params"]["forAllUsers"]="Y";n["params"]["delete"]="Y"}if(this._scope===BX.UI.EntityConfigScope.custom){n["params"]["userScopeId"]=this._userScopeId}BX.ajax.runComponentAction("bitrix:ui.form","saveConfiguration",{mode:"ajax",data:n}).then(function(){i.fulfill()});this._isChanged=false;return i},reset:function(t){var e={guid:this._id,params:{scope:this._scope},categoryName:this.categoryName};if(t){e["params"]["forAllUsers"]="Y"}var i=new BX.Promise;BX.ajax.runComponentAction("bitrix:ui.form","resetConfiguration",{mode:"ajax",data:e}).then(function(){i.fulfill()});return i},forceCommonScopeForAll:function(){var t=new BX.Promise;BX.ajax.runComponentAction("bitrix:ui.form","forceCommonScopeForAll",{mode:"ajax",data:{guid:this._id,categoryName:this.categoryName}}).then(function(){t.fulfill()});return t},getOption:function(t,e){return BX.prop.getString(this._options,t,e)},setOption:function(t,e){if(typeof e==="undefined"||e===null){return}if(BX.prop.getString(this._options,t,null)===e){return}this._options[t]=e;if(this._scope===BX.UI.EntityConfigScope.common){BX.userOptions.save(this.categoryName,this._id.toLowerCase()+"_common_opts",t,e,true)}else if(this._scope===BX.UI.EntityConfigScope.custom){BX.userOptions.save(this.categoryName,this._id.toLowerCase()+"_custom_opts_"+this._userScopeId,t,e,true)}else{BX.userOptions.save("crm.entity.editor",this._id+"_opts",t,e,false)}}};BX.UI.EntityConfig.create=function(t,e){var i=new BX.UI.EntityConfig;i.initialize(t,e);return i}}if(typeof BX.UI.EntityConfigItem==="undefined"){BX.UI.EntityConfigItem=function(){this._settings={};this._data={};this._name="";this._title=""};BX.UI.EntityConfigItem.prototype={initialize:function(t){this._settings=t?t:{};this._data=BX.prop.getObject(this._settings,"data",[]);this._name=BX.prop.getString(this._data,"name","");this._title=BX.prop.getString(this._data,"title","");this.doInitialize()},doInitialize:function(){},getType:function(){return""},getName:function(){return this._name},getTitle:function(){return this._title},toJSON:function(){return{}}}}if(typeof BX.UI.EntityConfigColumn==="undefined"){BX.UI.EntityConfigColumn=function(){BX.UI.EntityConfigColumn.superclass.constructor.apply(this);this._sections=[]};BX.extend(BX.UI.EntityConfigColumn,BX.UI.EntityConfigItem);BX.UI.EntityConfigColumn.prototype.doInitialize=function(){var t=BX.prop.getArray(this._data,"elements",[]);for(var e=0,i=t.length;e<i;e++){if(t[e].type==="section"||t[e].type==="included_area"){var n=BX.UI.EntityConfigFactory.createByType(t[e].type,{data:t[e]});this.addSection(n)}}};BX.UI.EntityConfigColumn.prototype.getType=function(){return BX.UI.EntityConfigType.COLUMN};BX.UI.EntityConfigColumn.prototype.getSections=function(){return this._sections};BX.UI.EntityConfigColumn.prototype.findSectionByName=function(t){var e=this.findSectionIndexByName(t);return e>=0?this._sections[e]:null};BX.UI.EntityConfigColumn.prototype.findSectionIndexByName=function(t){for(var e=0,i=this._sections.length;e<i;e++){var n=this._sections[e];if(n.getName()===t){return e}}return-1};BX.UI.EntityConfigColumn.prototype.findFieldByName=function(t){var e=this.findFieldIndexByName(t);return e>=0?this._sections[e]:null};BX.UI.EntityConfigColumn.prototype.findFieldIndexByName=function(t){for(var e=0,i=this._sections.length;e<i;e++){var n=this._sections[e];if(n.getName()===t){return e}}return-1};BX.UI.EntityConfigColumn.prototype.addSection=function(t){this._sections.push(t)};BX.UI.EntityConfigColumn.prototype.setSection=function(t,e){this._sections[e]=t};BX.UI.EntityConfigColumn.prototype.removeSectionByIndex=function(t){if(t<0||t>=this._sections.length){return false}this._sections.splice(t,1);return true};BX.UI.EntityConfigColumn.prototype.toJSON=function(){var t={name:this._name,type:this.getType(),data:BX.prop.getObject(this._data,"data",{}),elements:[]};for(var e=0,i=this._sections.length;e<i;e++){t.elements.push(this._sections[e].toJSON())}return t};BX.UI.EntityConfigColumn.create=function(t){var e=new BX.UI.EntityConfigColumn;e.initialize(t);return e}}if(typeof BX.UI.EntityConfigSection==="undefined"){BX.UI.EntityConfigSection=function(){BX.UI.EntityConfigSection.superclass.constructor.apply(this);this._fields=[]};BX.extend(BX.UI.EntityConfigSection,BX.UI.EntityConfigItem);BX.UI.EntityConfigSection.prototype.doInitialize=function(){this._fields=[];var t=BX.prop.getArray(this._data,"elements",[]);for(var e=0,i=t.length;e<i;e++){var n=BX.UI.EntityConfigField.create({data:t[e]});n.setIndex(e);this._fields.push(n)}};BX.UI.EntityConfigSection.prototype.getType=function(){return BX.UI.EntityConfigType.SECTION};BX.UI.EntityConfigSection.prototype.getFields=function(){return this._fields};BX.UI.EntityConfigSection.prototype.findFieldByName=function(t){var e=this.findFieldIndexByName(t);return e>=0?this._fields[e]:null};BX.UI.EntityConfigSection.prototype.findFieldIndexByName=function(t){for(var e=0,i=this._fields.length;e<i;e++){var n=this._fields[e];if(n.getName()===t){return e}}return-1};BX.UI.EntityConfigSection.prototype.addField=function(t){this._fields.push(t)};BX.UI.EntityConfigSection.prototype.setField=function(t,e){this._fields[e]=t};BX.UI.EntityConfigSection.prototype.removeFieldByIndex=function(t){var e=this._fields.length;if(t<0||t>=e){return false}this._fields.splice(t,1);return true};BX.UI.EntityConfigSection.prototype.toJSON=function(){var t={name:this._name,title:this._title,type:this.getType(),data:BX.prop.getObject(this._data,"data",{}),elements:[]};for(var e=0,i=this._fields.length;e<i;e++){t.elements.push(this._fields[e].toJSON())}return t};BX.UI.EntityConfigSection.create=function(t){var e=new BX.UI.EntityConfigSection;e.initialize(t);return e}}if(typeof BX.UI.EntityConfigIncludedArea==="undefined"){BX.UI.EntityConfigIncludedArea=function(){BX.UI.EntityConfigIncludedArea.superclass.constructor.apply(this);this._params={}};BX.extend(BX.UI.EntityConfigIncludedArea,BX.UI.EntityConfigItem);BX.UI.EntityConfigIncludedArea.prototype.doInitialize=function(){this._params=BX.prop.getObject(this._data,"data",{})};BX.UI.EntityConfigIncludedArea.prototype.getType=function(){return BX.UI.EntityConfigType.INCLUDED_AREA};BX.UI.EntityConfigIncludedArea.prototype.toJSON=function(){return{name:this._name,title:this._title,data:this._params,type:this.getType()}};BX.UI.EntityConfigIncludedArea.create=function(t){var e=new BX.UI.EntityConfigIncludedArea;e.initialize(t);return e}}if(typeof BX.UI.EntityConfigField==="undefined"){BX.UI.EntityConfigField=function(){BX.UI.EntityConfigField.superclass.constructor.apply(this);this._index=-1;this._optionFlags=0;this._options={}};BX.extend(BX.UI.EntityConfigField,BX.UI.EntityConfigItem);BX.UI.EntityConfigField.prototype.doInitialize=function(){this._optionFlags=BX.prop.getInteger(this._data,"optionFlags",0);this._options=BX.prop.getObject(this._data,"options",{})};BX.UI.EntityConfigField.prototype.toJSON=function(){var t={name:this._name};if(this._title!==""){t["title"]=this._title}t["optionFlags"]=this._optionFlags;t["options"]=this._options;return t};BX.UI.EntityConfigField.prototype.getIndex=function(){return this._index};BX.UI.EntityConfigField.prototype.setIndex=function(t){this._index=t};BX.UI.EntityConfigField.create=function(t){var e=new BX.UI.EntityConfigField;e.initialize(t);return e}}
//# sourceMappingURL=config.map.js